<template>
  <el-dialog :visible.sync="isShow" width="800px">
    <el-descriptions title="发货信息" :column="1" border>
      <el-descriptions-item label="订单编号">{{ itemModel.orderId }}</el-descriptions-item>
      <el-descriptions-item label="下单时间">{{ itemModel.createTime }}</el-descriptions-item>
      <el-descriptions-item label="收货人信息" :labelStyle="{width: '100px'}">
        <el-row>
         {{ itemModel.addrinfo.contactName }} {{ itemModel.addrinfo.contactPhone }}
        </el-row>
        <el-row>
          {{ itemModel.addrinfo.addrInfo }}
        </el-row>
        </el-descriptions-item>
    </el-descriptions>
    <el-tabs type="border-card" style="margin-top:20px" @tab-click="tabClick">
      <el-tab-pane label="无需物流">
        <el-row style="padding: 30px;">
          如果该物品无需物流运送(如虚拟产品、服务等)
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="物流信息">
        <el-form :model="form" :rules="rules" ref="form" label-width="80px" label-position="left" style="margin-left:50px">
          <el-form-item label="快递公司" prop="expressageCompany">
            <el-input v-model="form.expressageCompany" placeholder="请选择快递公司" clearable></el-input>
          </el-form-item>
          <el-form-item label="快递单号" prop="expressageNum">
            <el-input v-model="form.expressageNum" placeholder="请输入快递单号" clearable></el-input>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    
    <div class="bottom">
        <el-button type="primary" @click="confirm('form')" >确定</el-button>
        <el-button @click="close" >取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { request_post } from '@/api/common.js'

export default {
  components: {},
  data() {
    return {
        isShow: false,
        orderId: '',
        itemModel: {userModel:{},payWayAccountModel:{}, addrinfo: {}, remark: ''},
        form: {},
        openshopParams: {},
        rules: {
          // expressageCompany: [{ required: true, message: '请输入快递单号', trigger: 'blur' }]
        },
        adminOptions: [],
        currentTab: 0
    }
  },
  methods:{
    show(e){
      this.isShow = true
      this.orderId = e
      this.findOrderInfo()
    },
    close(){
        this.isShow = false
    },
    tabClick(e){
      this.currentTab = e.index
    },
    //确认
    confirm(formName){
        this.$refs[formName].validate((valid) => {
        if (valid) {
          var data = {
                orderId: this.orderId,
            }
          if(this.currentTab==1){
            data['expressageinfo'] = JSON.stringify(this.form)
          }else{
            data['expressageinfo'] = ''
          }
          request_post('/pay/order/sendItem/', data).then(res=>{
                if(res.data.code == 10000){
                  this.close()
                  this.$emit("confirm")
                  this.$message({
                      message: '操作成功',
                      type: 'success'
                  })
                }
            })
        }
      })
    },
    findOrderInfo(){
      request_post('/pay/order/getOrderInfoByOrderId/', {
        orderId: this.orderId
      }).then(res => {
        if(res.data.code == 10000){
          this.itemModel = res.data.data
          this.itemModel.createTime = this.itemModel.createTime.slice(0, 19).replace('T', ' ')
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.bottom{
    margin-top: 60px;
    display: flex;
    flex-direction: row;
    justify-content: center;
}
</style>
